{include file="common/_header"}
{include file="common/_header1"}

<body class="layui-anim layui-anim-up">
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">申购管理</a>
            <a>
              <cite>申购列表</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>

<div class="x-body">

    <!--    <xblock>-->
    <!--        &lt;!&ndash;            <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>&ndash;&gt;-->
    <!--        <button class="layui-btn" onclick="x_admin_show('添加商品','/products/boxeproduct?product_id=0',800,600)"><i class="layui-icon"></i>  添 加</button>-->
    <!--        &lt;!&ndash;            <span class="x-right" style="line-height:40px">共有数据：88 条</span>&ndash;&gt;-->
    <!--    </xblock>-->

    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
            <div class="layui-input-inline">
                <div class="layui-unselect layui-form-select shop_id" style="display:inline-block;">
                    <input type="text" name="product_name"  placeholder="请输入商品名称" value="{$data.get['product_name']}" autocomplete="off" class="layui-input">
                </div>
                {if !$data.isshop}
                <div class="layui-unselect layui-form-select shop_id" style="display:inline-block;">
                    <input type="text" name="shop_name"  placeholder="请输入商铺名称" value="{$data.get['shop_name']}" autocomplete="off" class="layui-input">
                </div>
                {/if}
                <div class="layui-unselect layui-form-select shop_id" style="display:inline-block;">
                    <select name="status_id">
                        <option value="">申请状态</option>
                        {if !empty($data.statuslist)}
                        {volist name="data.statuslist" id="vo"}
                        <option value="{$key}" {if $key == $data.get['status_id']}selected{/if}>{$vo}</option>
                        {/volist}
                        {/if}
                    </select>
                </div>
                <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
            </div>

        </form>
    </div>



    <table id="tables" class="layui-table">
        <thead>
        <tr>
            {if !$data.isshop}
            <th>商铺名称</th>
            {/if}
            <th>商品名称</th>
            <th>申购数量</th>
            <th>申购状态</th>
            <th>申购时间</th>
            <th>审核意见</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="data.data" id="vo"}
        <tr class="table_tr">
            {if !$data.isshop}
            <td>{$vo.shop_name}</td>
            {/if}
            <td>{$vo.product_name}</td>
            <td>{$vo.number}</td>
            <td>{$vo.status_name}</td>
            <td>{$vo.add_time|date="Y-m-d H:i:s"}</td>
            <td>{$vo.reason}</td>
            <td>
                <ul class="nav navbar-nav" style=" height: 40px; line-height: 10px;">
                    <li class="dropdown" style="height: 100%;">
                        {if $data.isshop}
                        {if $vo.status == 3}
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" style=" height: 100%; line-height: 5px;">
                            操作
                            <b class="caret"></b>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a title="确认收货"  onclick="suregoods('{$vo.p_r_id}')" href="javascript:;">确认收货</a></li>
                        </ul>
                        {/if}
                        {else /}
                            {if $vo.status == 2}
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" style=" height: 100%; line-height: 5px;">
                                操作
                                <b class="caret"></b>
                            </a>
                            <ul class="dropdown-menu">
                                <li><a title="确认发货"  onclick="suredelivery('{$vo.p_r_id}')" href="javascript:;">确认发货</a></li>
                            </ul>
                            {elseif $vo.status == 1 or $vo.status == 5}
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" style=" height: 100%; line-height: 5px;">
                                操作
                                <b class="caret"></b>
                            </a>
                            <ul class="dropdown-menu">
                                <li><a title="申购审核"  onclick="x_admin_show('申购审核', '/purchase/boxcheck?purchase_id={$vo.p_r_id}', '600', '400')" href="javascript:;">申购审核</a></li>
                            </ul>
                            {else /}
                            {/if}
                        {/if}
                    </li>
                </ul>
            </td>

        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page_all">
        {$page|raw}
    </div>
</div>
<script>


    $(function () {
        // 表格选中行的同时选中单选框
        $("#tables tr:gt(0)").click(function () {
            $(this).find(":radio").prop("checked", true);
        });

    });

    //js放到table下，才能检测到tr数组
    var trs = document.getElementById("tables").getElementsByTagName("tr");
    $(function () {
        for (var i = 0; i < trs.length; i++) {
            trs[i].onmousedown = function () {
                mousedownclick(this);
            }
        }
    });

    function mousedownclick(obj) {
        for (var j = 0; j < trs.length; j++) {
            if (trs[j] == obj) {
                if (trs[0] != obj) {
                    trs[j].style.background = '#D0E9C6';
                    // 启用新增和编辑按钮
                    $("#edits").removeAttr("disabled");//启用按钮
                    $('#edits').removeClass('layui-disabled');
                }
            } else {
                trs[j].style.background = '';
            }
        }
    }


    function opreate(id) {
        layer.confirm('您确定要删除该商品吗?', {btn: ['确定', '取消'], title: "提示"}, function () {
            $.ajax({
                url: 'delproduct?productid=' + id,
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    layer.msg(data.msg, {
                        icon: 6,
                        time: 500,
                    }, function () {
                        window.location.reload();
                    })
                }
            })
        });
    }

    function suredelivery(id) {
        layer.confirm('确定发货吗?', {btn: ['确定', '取消'], title: "提示"}, function () {
            $.ajax({
                url: 'suredelivery?purchase_id=' + id,
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    layer.msg(data.msg, {
                        icon: 6,
                        time: 500,
                    }, function () {
                        window.location.reload();
                    })
                }
            })
        });
    }

    function suregoods(id) {
        layer.confirm('您确定收货吗?', {btn: ['确定', '取消'], title: "提示"}, function () {
            $.ajax({
                url: 'suregoods?purchase_id=' + id,
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    layer.msg(data.msg, {
                        icon: 6,
                        time: 500,
                    }, function () {
                        window.location.reload();
                    })
                }
            })
        });
    }
</script>
</body>

{include file="common/_bottom"}